package com.example.jeong.yuejian10.Adapter;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.jeong.yuejian10.Activity.ActivityDetailActivity;
import com.example.jeong.yuejian10.Bean.ActivityBean;
import com.example.jeong.yuejian10.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.jeong.yuejian10.constant.Constant.ACTIVITY_PHOTO_URL;


public class ClubActAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContex;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;
    public ClubActAdapter(Context mContext,List mDataList){
        this.mContex = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext())
                .inflate(R.layout.cardview_club_activity, parent, false);
        return new ViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final ActivityBean entity = (ActivityBean) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.activity_name.setText(entity.getA_name());
        Log.d("sdf","activity_name");
        String pic = ACTIVITY_PHOTO_URL+entity.getA_picture();
        if (!pic.equals("")){
            Picasso.with(mContex).load(pic).error(R.drawable.ic_add).into(viewHolder.activity_pic);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("a_id",entity.getA_id());
                bundle.putString("a_name",entity.getA_name());
                bundle.putInt("a_price",entity.getA_price());
                bundle.putString("a_address",entity.getA_address());
                bundle.putString("a_time",entity.getA_time());
                bundle.putString("a_picture",entity.getA_picture());
                bundle.putString("a_phone",entity.getA_phone());
                Intent intent=new Intent(mContex, ActivityDetailActivity.class);
                intent.putExtras(bundle);
                mContex.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView activity_pic;
        TextView activity_name;

        public ViewHolder(View itemView){
            super(itemView);
            activity_name = (TextView) itemView.findViewById(R.id.activity_name);
            activity_pic = (ImageView) itemView.findViewById(R.id.pic);
        }
    }
}